package com.jia.lightrailsystem

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class BootReceiver : BroadcastReceiver() {
    companion object {
        private const val TAG = "BootReceiver"
        private const val ACTION = "android.intent.action.BOOT_COMPLETED"
    }
    override fun onReceive(context: Context?, intent: Intent?) {
        val action = intent?.action
        //Log.d(TAG, "BootReceiver onReceive:$action")
        if (ACTION == intent?.action) {
            startApp(context)
        }
    }
    private fun startApp(context: Context?) {
//        val intent = Intent(context, StartPageActivity::class.java)
//        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
//        context?.startActivity(intent)
        println("BootReceiver onReceive:...bootComplete!")
        val newIntent = Intent(context, MainActivity::class.java)
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) // 注意，必须添加这个标记，否则启动会失败
        context?.startActivity(newIntent)
    }
}